﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WF.DAL;

namespace WF.Model
{
    public class NameValuePairEntity : EntityBase<DAL.NameValuePair>
    {
        #region 构造函数

        public NameValuePairEntity() : base() { }

        public NameValuePairEntity(NameValuePair nameValuePair)
            : base(nameValuePair) { }
        #endregion

        #region 实现基类abstract属性

        public override string ID
        {
            get
            {
                return DbEntity.ID;
            }
            set
            {
                DbEntity.ID = value; this.SendPropertyChanged("ID");
            }
        }

        public override string DisplayName
        {
            get { return DbEntity.ID; }
        }

        #endregion

        #region Public 属性


        public string Category
        {
            get { return DbEntity.Category; }
            set { DbEntity.Category = value; this.SendPropertyChanged("Category"); }
        }

        public string Name
        {
            get { return DbEntity.Name; }
            set { DbEntity.Name = value; this.SendPropertyChanged("Name"); }
        }

        public string Value
        {
            get { return DbEntity.Value; }
            set { DbEntity.Value = value; this.SendPropertyChanged("Value"); }
        }

        public int ParentID
        {
            get { return DbEntity.ParentID; }
            set { DbEntity.ParentID = value; this.SendPropertyChanged("ParentID"); }
        }

        public int SortOrder
        {
            get { return DbEntity.SortOrder; }
            set { DbEntity.SortOrder = value; this.SendPropertyChanged("SortOrder"); }
        }
        #endregion

        #region Converter
        public static NameValuePairEntity CreateEntityFromDb(NameValuePair nameValuePair)
        {
            if (null == nameValuePair) return null;
            NameValuePairEntity ret = new NameValuePairEntity(nameValuePair);
            return ret;
        }

        public static NameValuePair CreateDbFromEntity(NameValuePairEntity nameValuePairEntity)
        {
            if (null == nameValuePairEntity) return null;

            //NameValuePair ret = new NameValuePair();
            //ret.Category = nameValuePairEntity.Category;
            //ret.ID = nameValuePairEntity.NameValuePairID;
            //ret.Name = nameValuePairEntity.Name;
            //ret.ParentID = nameValuePairEntity.ParentID;
            //ret.SortOrder = nameValuePairEntity.SortOrder;
            //ret.Value = nameValuePairEntity.Value;
            return nameValuePairEntity.DbEntity;
        }

        public static void UpdateDbFromEntity(NameValuePairEntity nameValuePairEntity, NameValuePair nameValuePair)
        {
            if ((null != nameValuePairEntity) && (null != nameValuePair) && (nameValuePairEntity.ID == nameValuePair.ID))
            {
                nameValuePair.Category = nameValuePairEntity.Category;
                nameValuePair.Name = nameValuePairEntity.Name;
                nameValuePair.ParentID = nameValuePairEntity.ParentID;
                nameValuePair.SortOrder = nameValuePairEntity.SortOrder;
                nameValuePair.Value = nameValuePairEntity.Value;
            }
        }
        //public void CopyFrom(NameValuePairEntity nameValuePairEntity)
        //{
        //    this._DALObject = nameValuePairEntity._DALObject;
        //}
        #endregion

        //#region IEntity

        //public string ID
        //{
        //    get { return DbEntity.ID.ToString(); }
        //    set { DbEntity.ID = int.Parse(value); }
        //}

        //public bool Add(WF.IDataLayer DataLayer)
        //{
        //    //return DataLayer.Add(this);
        //    throw new NotImplementedException();
        //}

        //public bool Update(WF.IDataLayer DataLayer)
        //{
        //    //return DataLayer.Update(this);
        //    throw new NotImplementedException();
        //}

        //public bool Delete(WF.IDataLayer DataLayer)
        //{
        //    //return DataLayer.DeleteNameValuePairEntity(this.ID);
        //    throw new NotImplementedException();
        //}

        //public bool GetDetail(WF.IDataLayer DataLayer)
        //{
        //    //JobEntity result;
        //    //if (!DataLayer.GetNameValuePairEntityById(this.ID, out result))
        //    //{
        //    //    return false;
        //    //}
        //    //this._DALObject = result._DALObject;
        //    //return true;
        //    throw new NotImplementedException();
        //}
        //#endregion
    }
}
